package vn.sunnet.game.SinhTon.object;

import vn.sunnet.game.SinhTon.global.Assets;
import vn.sunnet.game.SinhTon.global.Position;
import vn.sunnet.game.SinhTon.global.Setting;

import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;

// Thiết bị nổ (Skill game)
public class ExplosiveDevice {
	private int id;
	private String name;
	private int damage; // máu
	private int damageRegion; // bán kính sát thương
	private float timeReload, timeReusable; // Thời gian load lai
	private int coinValue; // xu
	private boolean isBuy; // Skill da mua hay chua mua
	private Animation animation;
	private float stateTime;
	private boolean isReload, isUse; // la load lai hay ko? va da su dung dk hay
										// chua?
	private float x, y;
	private Rectangle bound; // hinh chu nhat bao hinh skill

	public ExplosiveDevice(int id, boolean isBuy) {
		this.isBuy = isBuy;
		this.id = id;
		switch (id) {
		case 1:
			x = Position.X_ROCKET;
			y = Position.Y_ROCKET;
			animation = new Animation(0.2f, Assets.trSkillRocket);
			damage = 30;
			damageRegion = 200;
			timeReload = 25;
			coinValue = 2000;
			break;

		case 2:
			x = Position.X_FREEZE;
			y = Position.Y_FREEZE;
			animation = new Animation(0.2f, Assets.trSkillFreeze);
			damageRegion = 1280;
			timeReload = 30;
			coinValue = 2800;
			break;
		case 3:
			x = Position.X_GRENADE;
			y = Position.Y_GRENADE;
			animation = new Animation(0.2f, Assets.trSkillLuuDan);
			damage = 60;
			damageRegion = 1280;
			timeReload = 35;
			coinValue = 3500;
			break;
		}

		bound = new Rectangle(id == 3 ? x + 23 : x + 18, id == 1 ? y + 13
				: y + 23, 64, 76);
	}

	// Neu ma chua su dung duoc thi animation dung yen
	public TextureRegion getTexture() {
		if (!isUse)
			stateTime = 0;
		// return Assets.trSkillGame.get(id - 1);
		return animation.getKeyFrame(stateTime, true);
	}

	public TextureRegion getTextureReloadSkill() {
		return Assets.trImage.get(15);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public int getDamageRegion() {
		return damageRegion;
	}

	public int getDamage() {
		return damage;
	}

	public float getTimeReload() {
		return timeReload;
	}

	public int getCoinValue() {
		return coinValue;
	}

	public boolean isBuy() {
		return isBuy;
	}

	public void update(float time) {
		stateTime += time;
		if (this.isBuy()) {
			if (!isUse)
				timeReusable += time;
			// Khi dong bang se mat 10s thuc hien dong bang sau do moi bat dau
			// load lai
			if (this.getId() == 2) {
				if (timeReusable > timeReload) {
					setUse(true);
					timeReusable = -10;
				}
			} else if (timeReusable > timeReload) {
				setUse(true);
				if (Setting.getBoolean(Setting.SOUND))
					Assets.arrSoundGamePlay.get(6 + id).play(1f);
				timeReusable = 0;
			}
		}
	}

	public boolean isReload() {
		return isReload;
	}

	public void setReload(boolean isReload) {
		this.isReload = isReload;
	}

	public Rectangle getBound() {
		return bound;
	}

	public float getY() {
		return y;
	}

	public float getX() {
		return x;
	}

	public float getTimeReusable() {
		return timeReusable;
	}

	public boolean isUse() {
		return isUse;
	}

	public void setUse(boolean isUse) {
		this.isUse = isUse;
	}
}